<%-- 
    Document   : userView
    Created on : 20.6.2014, 19:55:18
    Author     : Michal Ďuriš
--%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <%@include file="../jspf/resources.jspf" %>
        
        <title>Detail užívatela</title>
    </head>
    <body>

        <%@include file="../jspf/header.jspf" %>

        <fieldset>
            <legend>Užívatel</legend>
            <c:choose>
                <c:when test="${not empty user}" >

                    <fieldset>
                        <legend>Osobné údaje</legend>
                        Meno: <c:out value="${user.name}" /> 

                        <c:if test="${not empty user.favoriteBook}">
                            <br />
                            Oblúbená kniha: <c:out value="${user.favoriteBook.title}" />
                        </c:if>

                        <c:if test="${not empty user.preferredAccount}" >
                            <br />
                            Preferovaný účet: <c:out value="${user.preferredAccount.name}" />
                        </c:if>
                    </fieldset>

                    <fieldset>
                        <legend>Knihy</legend>

                        <table class="entityViewTable" >

                            <thead>
                                <tr>
                                    <th>Titul</th>
                                    <th>Popis</th>
                                    <th>Akcie</th>
                                </tr>
                            </thead>

                            <tbody>
                                <c:forEach items="${user.books}" var="book">
                                    <tr>
                                        <td>
                                            <c:out value="${book.title}" />
                                        </td>
                                        <td>
                                            <c:out value="${book.description}" />
                                        </td>
                                        <td>
                                            <a href="<c:url value="/admin/editor/book/${book.id}?userID=${user.id}"/>">zmeň</a>
                                            <a href="<c:url value="/admin/editor/delete/book/${book.id}?userID=${user.id}"/>">zmaž</a>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </tbody>

                        </table>

                        <a href="<c:url value="/admin/editor/book?userID=${user.id}" />" >pridaj knihu</a>
                    </fieldset>

                    <fieldset>
                        <legend>Účty</legend>

                        <table class="entityViewTable" >

                            <thead>
                                <tr>
                                    <th>Názov</th>
                                    <th>Kompletné číslo účtu</th>
                                    <th>Akcie</th>
                                </tr>
                            </thead>

                            <tbody>
                                <c:forEach items="${user.accounts}" 
                                           var="account" >

                                    <tr>
                                        <td>
                                            <c:out value="${account.name}" />
                                        </td>
                                        <td>
                                            <c:if test="${not empty account.accountPrefix}" >
                                                <c:out value="${account.accountPrefix} - " />
                                            </c:if>
                                            <c:out value="${account.accountNumber} / ${account.bankCode}" />
                                        </td>
                                        <td>
                                            <a href="<c:url value="/admin/editor/account/${account.id}?userID=${user.id}"/>" >zmeň</a>
                                            <a href="<c:url value="/admin/editor/delete/account/${account.id}?userID=${user.id}"/>" >zmaž</a>
                                        </td>
                                    </tr>

                                </c:forEach>
                            </tbody>

                        </table>

                        <a href="<c:url value="/admin/editor/account?userID=${user.id}" />" >pridaj účet</a>
                    </fieldset>

                </c:when>

                <c:otherwise>
                    <span style="color: red;" >Užívatel nie je dostupný...</span>
                </c:otherwise>

            </c:choose>

        </fieldset>

        <%@include file="../jspf/footer.jspf" %>

    </body>
</html>
